﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Windows.Forms.Design;
using System.Windows.Forms.Design.Behavior;
//using System.ComponentModel;
using System.ComponentModel.Design;

namespace Schüleranmeldung.Controls
{
    [Designer(typeof(UserControlSnapLineDesigner))]
    public partial class ResetTextBox : UserControl
    {
        public ResetTextBox()
        {
            InitializeComponent();
        }

        private string resetText;

        public override string Text
        {
            get
            {
                return txtText.Text;
            }
            set
            {
                txtText.Text = value;
                resetText = value;
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            Text = resetText;
        }

        public TextBox TextBox
        {
            get
            {
                return txtText;
            }
        }

        private class UserControlSnapLineDesigner : ControlDesigner
        {
            public override IList SnapLines
            {
                get
                {
                    /* Code from above */
                    IList snapLines = base.SnapLines;

                    // *** This will need to be modified to match your user control
                    ResetTextBox control = Control as ResetTextBox;
                    if (control == null) { return snapLines; }

                    // *** This will need to be modified to match the item in your user control
                    // This is the control in your UC that you want SnapLines for the entire UC
                    IDesigner designer = TypeDescriptor.CreateDesigner(
                        control.TextBox, typeof(IDesigner));
                    if (designer == null) { return snapLines; }

                    // *** This will need to be modified to match the item in your user control
                    designer.Initialize(control.TextBox);

                    using (designer)
                    {
                        ControlDesigner boxDesigner = designer as ControlDesigner;
                        if (boxDesigner == null) { return snapLines; }

                        foreach (SnapLine line in boxDesigner.SnapLines)
                        {
                            if (line.SnapLineType == SnapLineType.Baseline)
                            {
                                // *** This will need to be modified to match the item in your user control
                                snapLines.Add(new SnapLine(SnapLineType.Baseline,
                                    line.Offset + control.TextBox.Top,
                                    line.Filter, line.Priority));
                                break;
                            }
                        }
                    }
                    return snapLines;
                }
            }
        }

    }
}
